//
//  SHAuthFourthStatusPutPhoneController.m
//  JiFengDaRen
//
//  Created by SH_iOS on 2017/7/18.
//  Copyright © 2017年 SH_iOS. All rights reserved.
//
//首瀚银行卡四要素认证通过，修改手机号码
#import "SHAuthFourthStatusPutPhoneController.h"

@interface SHAuthFourthStatusPutPhoneController ()<UITextFieldDelegate>
@property (nonatomic,strong)   UILabel     *changeLabel;
@property (nonatomic,strong)   UITextField *changeTf;
@property (nonatomic,strong)   UIButton    *determineBtn;
@property (nonatomic,strong)   UIView     *firstBgView;

@end

@implementation SHAuthFourthStatusPutPhoneController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"修改手机号";
    [self configUI];
}
- (void)configUI{
    
    self.view.backgroundColor = KBASEBGCOLOR;
    self.firstBgView = [[UIView alloc]init];
    self.firstBgView.layer.borderWidth = 0.5;
    self.firstBgView.layer.borderColor = KLINECOLOR.CGColor;
    self.firstBgView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.firstBgView];
    [self.firstBgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view.mas_top).with.offset(__I6Height(20));
        make.left.equalTo(self.view.mas_left).with.offset(__I6Width(0));
        make.right.equalTo(self.view.mas_right).with.offset(__I6Width(0));
        make.height.mas_equalTo(__I6Height(44));
        
        
    }];
    
    
    
    self.changeLabel = [[UILabel alloc]init];
    self.changeLabel.textColor = [UIColor colorWithHexString:@"#474958"];
    self.changeLabel.font = KSHSystemFont(12);
    [self.firstBgView addSubview:self.changeLabel];
    [self.changeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.firstBgView.mas_left).with.offset(0);
        make.centerY.mas_equalTo(self.firstBgView.mas_centerY);
        make.width.mas_equalTo(0);
        make.height.mas_equalTo(__I6Height(20));
    }];
    
    
    self.changeTf =  [[UITextField alloc]init];
    self.changeTf.delegate = self;
    self.changeTf.font = KSHSystemFont(14);
    self.changeTf.textColor = [UIColor blackColor];
    [self.changeTf  setValue:[UIColor colorWithHexString:@"#c0c0c7"] forKeyPath:@"_placeholderLabel.textColor"];
    [self.changeTf setValue:KSHSystemFont(14) forKeyPath:@"_placeholderLabel.font"];
    self.changeTf.clearButtonMode = UITextFieldViewModeAlways;
    [self.firstBgView addSubview:self.changeTf];
    [self.changeTf mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.changeLabel.mas_left).with.offset(__I6Width(15));
        make.right.mas_equalTo(self.firstBgView.mas_right).with.offset(__I6Width(-15));
        make.centerY.mas_equalTo(self.firstBgView.mas_centerY);
        make.height.mas_equalTo(__I6Height(42));
    }];
    
    self.changeLabel.text = @"手机号";
    self.changeTf.placeholder = @"请输入银行卡预留手机号";
    [self.firstBgView addSubview:self.changeTf];
    
    self.determineBtn = [[UIButton alloc]init];
    self.determineBtn.backgroundColor = KREDCOLOR;
    self.determineBtn.layer.cornerRadius = __I6Width(5);
    self.determineBtn.layer.masksToBounds = YES;
    self.determineBtn.titleLabel.font = KSHSystemFont(__I6Width(17));
    [self.determineBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [self.determineBtn setTitle:@"立即修改" forState:UIControlStateNormal];
    // [self.determineBtn setBackgroundImage:[UIImage imageNamed:@"loginHilight"] forState:UIControlStateHighlighted];
    [self.determineBtn addTarget:self action:@selector(changeNickNameOrEmail:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview: self.determineBtn];
    [self.determineBtn  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.firstBgView.mas_bottom).with.offset(__I6Height(50));
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.width.mas_equalTo(__I6Width(326));
        make.height.mas_equalTo(__I6Height(42));
        
    }];
    
    
}

- (void)changeNickNameOrEmail:(UIButton *)sender {
    [self.view endEditing:YES];
    if (self.changeTf.text.length == 0){
        [self.view makeToast:@"请填写银行卡预留手机号" duration:2 position:@"center"];
        return;
    }
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    [SHUserCenterHttp putBankCardPhoneWithCardNo:self.bankCardModel.bank_card_code phone:self.changeTf.text success:^(id result) {
        [MBProgressHUD hideHUDForView:self.view animated:YES ];
        dispatch_time_t delayTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5/*延迟执行时间*/ * NSEC_PER_SEC));
        
        dispatch_after(delayTime, dispatch_get_main_queue(), ^{
            
            [[NSNotificationCenter defaultCenter] postNotificationName:@"refreshCashCardNotification" object:nil];
            [self.navigationController popViewControllerAnimated:YES];
            
            
        });

    } complection:^(id result) {
        [MBProgressHUD hideHUDForView:self.view animated:YES ];
        

    } failure:^(id erro) {
        [MBProgressHUD hideHUDForView:self.view animated:YES ];

    }];
   
}



#pragma mark --- 文本框代理

- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [textField resignFirstResponder];
    return YES;
    
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    [self.view endEditing:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
